package org.gushi.algorithm.a04;

public class SelectionSort<E extends Comparable<E>> {
    private E[] list;


    public SelectionSort(E[] list) {
        this.list = list;
    }


    public E[] sort() {
        for (int i = 0; i < list.length; i++) {
            E element = list[i];
            boolean isExit = false;
            int index = 0;
            /*
             * 循环找到最小数
             */
            for (int j = i+1; j < list.length ; j++) {
                if (element.compareTo(list[j]) > 0) {
                    element = list[j];
                    isExit = true;
                    index = j;
                }
            }
            // 然后交换位置
            if(isExit && index !=0){
                list[index] = list[i];
                list[i] = element;
            }

        }

        return list;


    }

}
